package com.itheima.controller;


import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/save")
    public String save(User user){
        userService.save(user);
        return "redirect:/user/show.do";
    }

    @RequestMapping("/show")
    public String show(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("list",userList);
        return "list";
    }

}
